import { BrowserRouter, Routes, Route } from 'react-router-dom'
import { routeConfig } from './routeList'
import { BASE_NAME } from '@/config/global.js'

const renderRoutes = (routes) => {
  return routes.map((item, index) => {
    if (item && item.children) {
      return (
        <Route
          path={item.path} 
          element={item.element} 
          key={index}>
          {renderRoutes(item.children)}
        </Route>
      );
    } else {
      return (
        <Route path={item.path} element={item.element} key={index}></Route>
      )
    }
  })
}

export const getRenderRoutes = () => {
  return (
    <BrowserRouter basename={BASE_NAME}>
      <Routes>{renderRoutes(routeConfig)}</Routes>
    </BrowserRouter>
  )
}


